<?php
$widget_params = isset($widget_params) ? $widget_params : [];
$choice_from = \Illuminate\Support\Arr::get($widget_params, 'from', 'from');
$choice_to = \Illuminate\Support\Arr::get($widget_params, 'to', 'to');
$choice_name = \Illuminate\Support\Arr::get($widget_params, 'name', '日期');
$choice_search = isset($search) ? $search : \Illuminate\Support\Facades\Request::all();
?>
<div class="layui-input-inline">
    <input class="layui-input data_range" placeholder="开始{{$choice_name}}" autocomplete="off" name="{{$choice_from}}"
           id="data_range_{{$choice_from}}" value="{{\Illuminate\Support\Arr::get($choice_search,$choice_from,'')}}">
</div>
<div class="layui-input-inline">
    <input class="layui-input data_range" placeholder="截止{{$choice_name}}" autocomplete="off" name="{{$choice_to}}"
           id="data_range_{{$choice_to}}" value="{{\Illuminate\Support\Arr::get($choice_search,$choice_to,'')}}">
</div>
@push('js')
    <script>
        layui.use(["laydate"], function () {
            var laydate = layui.laydate;
            var data_range_from = laydate.render({
                elem: '#data_range_{{$choice_from}}',
                type: 'date',
                btns: ['confirm'],
                done: function (value, date) {
                    data_range_to.config.min = getDateArray(date);
                }
            });
            var data_range_to = laydate.render({
                elem: '#data_range_{{$choice_to}}'
                , type: 'date'
                , btns: ['confirm']
                , done: function (value, date) {
                    data_range_from.config.max = getDateArray(date);
                }
            });

            function getDateArray(date) {
                var formatDate = {};
                formatDate.year = date.year;
                formatDate.month = date.month - 1;
                formatDate.date = date.date;
                return formatDate;
            }
        });

    </script>
@endpush
